package cn.kelvin.stack;

import java.util.Scanner;

public class MatchTest {
	
	@SuppressWarnings("resource")
	public static void main(String[] args) {
//		System.out.println(Integer.valueOf('{'));
//		System.out.println(Integer.valueOf('}'));
//		System.out.println(Integer.valueOf('['));
//		System.out.println(Integer.valueOf(']'));
//		System.out.println(Integer.valueOf('('));
//		System.out.println(Integer.valueOf(')'));
		String input = new Scanner(System.in).nextLine();
		System.out.println(isMatch(input));
	}
	
	public static boolean isMatch(String matchStr){
		MyStack<Integer> stack = new MyStack<>();
		char[] chs = matchStr.toCharArray();
		for(int i=0;i<chs.length;i++){
			if(chs[i]=='(' || chs[i]=='[' || chs[i]=='{'){
				stack.push(Integer.valueOf(chs[i]));
			}else {
				if(stack.isEmpty()){
					System.out.println("stack empty");
					return false;
				}else{
					if(')'==chs[i]){
						if((stack.getTop()+1)==Integer.valueOf(chs[i])){
							stack.pop();
						}else{
							System.out.println("not match");
							return false;
						}
					}else if(']'==chs[i] || '}'==chs[i]){
						if((stack.getTop()+2)==Integer.valueOf(chs[i])){
							stack.pop();
						}else{
							System.out.println("not match");
							return false;
						}
					}
				}
			}
		}
		if(stack.isEmpty()){
			return true;
		}
		return false;
	}
}
